/*****************************************************************************/
/*                  Perot Systems Framework                                  */
/*****************************************************************************/
/* Stored Procedure :: LogException()                                        */
/* Log an Exception                                                         */
/*****************************************************************************/
/* Copyright (C) 2003, Perot Systems Corporation. All right reserved.        */
/* Developer: Dmitry Frenkel (dima.frenkel@ps.net)                           */
/* Started:  07/07/2003                                                      */
/*****************************************************************************/
/* Modifications                                                             */
/* Date       |  Author          | Description                               */
/*------------+------------------+-------------------------------------------*/
/*            |                  |                                           */
/*****************************************************************************/

/******************************************************************************/
/* Step 0. Preparations/Declarations                                          */
/******************************************************************************/
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

/******************************************************************************/
/* Step 1. Remove stored procedure if it already exists                       */
/******************************************************************************/
IF (SELECT OBJECT_ID('[DBO].[LogException]')) IS NOT NULL
BEGIN
  DROP PROCEDURE [DBO].LogException
END

GO

/*****************************************************************************/
/* Stored Procedure :: LogException()                                        */
/*****************************************************************************/
/* Copyright (C) 2003, Perot Systems Corporation. All right reserved.        */
/* Developer: Dmitry Frenkel (dima.frenkel@ps.net)                           */
/* Started:  07/07/2003                                                      */
/*****************************************************************************/
CREATE PROCEDURE [DBO].LogException( @Source VARCHAR( 64 ),
                                     @Description VARCHAR( 1024 ),
                                     @Severity SMALLINT,
                                     @HResult BIGINT = 0,
                                     @DTS DATETIME = NULL,
                                     @StackTrace VARCHAR( 1024 ) = '',
                                     @User VARCHAR( 64 ) = '',
                                     @Server VARCHAR( 32 ) = '',
                                     @SessionID VARCHAR( 128 ) = '' )
AS  
BEGIN
  DECLARE @newOID BIGINT
  IF (@DTS IS NULL) SET @DTS = GetDate()
  -- 1.1. Perform insert (OID is identity)
  INSERT INTO ExceptionLog( DTS, HResult, Source, Description, Severity, StackTrace, [User], Server, SessionID )
  VALUES( @DTS, @HResult, @Source, @Description, @Severity, @StackTrace, @User, @Server, @SessionID )
  -- 1.2. Determine OID of newly inserted object
  SET @newOID =  @@IDENTITY
  -- 1.3. Retutn OID and timestamp of newly inserted object
  SELECT OID, timestamp 
    FROM ExceptionLog 
    WHERE OID = @newOID
END 
GO

/******************************************************************************/
/* Step 3. Assign appropriate permissions                                     */
/******************************************************************************/
GRANT EXECUTE ON [DBO].LogException TO [Liberty_Users]
GO
-- Developers and Admins have permissions to execute through membership  